<?php

namespace Home\Controller;

use Think\Page;
use Think\Verify;
class YuanxiaoController extends BaseController {
    

    public function index(){
    

        $oid = I('oid');
        if($oid){
            session('openid',$oid);
        }
    
        $openid = session('openid');
        if(is_weixin() == true &&  !$openid && !$oid){

            $urlurl  = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
            $urlurl = urlencode($urlurl);
    
            $url = "http://c3w.cc/entry/click?ReturnUrl=".$urlurl;
            header("Location:".$url);
            exit;
        }

        
        // 如果是手机跳转到 手机模块
        // if(true == isMobile()){
        //     header("Location: ".U('Mobile/Index/index'));
        //     exit;
        // }
        

        $this->display();
    }


    public function post(){
        $post = I('post.');
        $sum = 0;
        $openid = session('openid');
        
        if($post['name1'] && $post['mobile1']){
            M('yuanxiao')->data(array('name'=>$post['name1'],'mobile'=>$post['mobile1'],'openid'=>$openid))->add();
            $sum ++;
        }

        if($post['name2'] && $post['mobile2']){
            M('yuanxiao')->data(array('name'=>$post['name2'],'mobile'=>$post['mobile2'],'openid'=>$openid))->add();
            $sum ++;
        }

        if($post['name3'] && $post['mobile3']){
            M('yuanxiao')->data(array('name'=>$post['name3'],'mobile'=>$post['mobile3'],'openid'=>$openid))->add();
            $sum ++;
        }

        if($post['name4'] && $post['mobile4']){
            M('yuanxiao')->data(array('name'=>$post['name4'],'mobile'=>$post['mobile4'],'openid'=>$openid))->add();
            $sum ++;
        }

        if($post['name5'] && $post['mobile5']){
            M('yuanxiao')->data(array('name'=>$post['name5'],'mobile'=>$post['mobile5'],'openid'=>$openid))->add();
            $sum ++;
        }

        if($post['name6'] && $post['mobile6']){
            M('yuanxiao')->data(array('name'=>$post['name6'],'mobile'=>$post['mobile6'],'openid'=>$openid))->add();
            $sum ++;
        }


        if($post['name7'] && $post['mobile7']){
            M('yuanxiao')->data(array('name'=>$post['name7'],'mobile'=>$post['mobile7'],'openid'=>$openid))->add();
            $sum ++;
        }


        if($post['name8'] && $post['mobile8']){
            M('yuanxiao')->data(array('name'=>$post['name8'],'mobile'=>$post['mobile8'],'openid'=>$openid))->add();
            $sum ++;
        }

        if($post['name9'] && $post['mobile9']){
            M('yuanxiao')->data(array('name'=>$post['name9'],'mobile'=>$post['mobile9'],'openid'=>$openid))->add();
            $sum ++;
        }

        $this->success('成功录入'.$sum.'条');
    }


    public function chacun(){


        $this->display();
    }

    public function query(){
        $name = I('name');

        //$con['name'] = array('like','%'.$name.'%');
        $con['name'] = $name;
        $res = M('yuanxiao')->where($con)->find();

        $this->assign('res',$res);
        $this->display();
    }

 
}